package sistema.usuario.dao;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;

import com.thoughtworks.xstream.XStream;

import util.CAoSFileWritter;
import util.InvalidFileException;

public class UsuarioFileWriter implements CAoSFileWritter {

	/* (non-Javadoc)
	 * @see util.CAoSFileWritter#processFile(java.lang.String, java.lang.Object)
	 */
	public void processFile(String file, Object object) throws InvalidFileException {
		XStream xstream = new XStream();
		xstream.alias("Usuarios", HashMap.class);
        String xml = xstream.toXML(object);

        BufferedWriter textWriter = null;
        try {
            textWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
                    file), "UTF-8"));
            
            textWriter.write(xml);
        } catch (Exception e) {
        	//e.printStackTrace();
            throw new InvalidFileException("Arquivo  n�o pode ser gravado.", e);
        } finally {
            try {
                textWriter.close();
            } catch (IOException e) {
                //e.printStackTrace();
            }
        }
	}

}
